package com.iseastar.guojiang.team.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.iseastar.guojiang.model.CourierTeamPastAchievementsBean;
import com.iseastar.guojiang.util.HandlerTime;
import com.shouhuobao.station.R;
import com.shouhuobao.take.utils.DateUtils;

import java.util.ArrayList;
import java.util.Date;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * 战队过往成就
 * Created by lidandan on 2018/6/13.
 */
public class CourierTeamPastAchievementsAdapter extends BaseAdapterExt<CourierTeamPastAchievementsBean> {

    public CourierTeamPastAchievementsAdapter(ArrayList<CourierTeamPastAchievementsBean> items, Activity context) {
        super(items, context);
        setEmptyView(R.layout.courier_team_past_achievements_empty);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.courier_team_rank_item, parent, false);
            holder.mYearTV = (TextView) convertView.findViewById(R.id.year_tv);
            holder.mMonthTV = (TextView) convertView.findViewById(R.id.month_tv);
            holder.mAmountWarZoneTV = (TextView) convertView.findViewById(R.id.amount_war_zone_tv);
            holder.mAmountProvinceTV = (TextView) convertView.findViewById(R.id.amount_province_tv);
            holder.mAmountCountryTV = (TextView) convertView.findViewById(R.id.amount_country_tv);
            holder.mMileageWarZoneTV = (TextView) convertView.findViewById(R.id.mileage_war_zone_tv);
            holder.mMileageProvinceTV = (TextView) convertView.findViewById(R.id.mileage_province_tv);
            holder.mMileageCountryTV = (TextView) convertView.findViewById(R.id.mileage_country_tv);
            holder.mMincomeWarZoneTV = (TextView) convertView.findViewById(R.id.income_war_zone_tv);
            holder.mMincomeProvinceTV = (TextView) convertView.findViewById(R.id.income_province_tv);
            holder.mMincomeCountryTV = (TextView) convertView.findViewById(R.id.income_country_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CourierTeamPastAchievementsBean item = getItem(position);
        String[] year = new String[]{};
        if (item.getYear().equals(DateUtils.getDateYYYYMMFormat().format(new Date()).substring(0, 4))) {
            holder.mYearTV.setVisibility(View.GONE);
        } else {
            if (position>0){
                if (getItem(position).getYear().equals(getItem(position-1).getYear())){
                    holder.mYearTV.setVisibility(View.GONE);
                }else {
                    holder.mYearTV.setVisibility(View.VISIBLE);
                }
            }else {
                holder.mYearTV.setVisibility(View.VISIBLE);
            }
            holder.mYearTV.setText(item.getYear() + "年");
        }

        holder.mMonthTV.setText(HandlerTime.monthStr(item.getMonth()));
        //战区排名
        holder.mAmountWarZoneTV.setText(item.getStoreOrderCntTop() + "");
        holder.mAmountProvinceTV.setText(item.getStoreDistinceTop() + "");
        holder.mAmountCountryTV.setText(item.getStoreProfitTop() + "");
        //省排名
        holder.mMileageWarZoneTV.setText(item.getProvinceOrderCntTop() + "");
        holder.mMileageProvinceTV.setText(item.getProvinceDistinceTop() + "");
        holder.mMileageCountryTV.setText(item.getProvinceProfitTop() + "");
        //全国排名
        holder.mMincomeWarZoneTV.setText(item.getCountryOrderCntTop() + "");
        holder.mMincomeProvinceTV.setText(item.getCountryDistinceTop() + "");
        holder.mMincomeCountryTV.setText(item.getProvinceProfitTop() + "");
        return convertView;
    }

    class ViewHolder {
        private TextView mYearTV;
        private TextView mMonthTV;
        private TextView mAmountWarZoneTV;
        private TextView mAmountProvinceTV;
        private TextView mAmountCountryTV;
        private TextView mMileageWarZoneTV;
        private TextView mMileageProvinceTV;
        private TextView mMileageCountryTV;
        private TextView mMincomeWarZoneTV;
        private TextView mMincomeProvinceTV;
        private TextView mMincomeCountryTV;
    }
}
